package game;
		
import java.io.*;
import java.net.*;

public class WorkerRunnable implements Runnable
{
	private Socket clientSocket = null;
	private String line = "";
	
	
	public WorkerRunnable(Socket clientSocket)
	{
		this.clientSocket = clientSocket;
	}
	
	public void run()
	{
		try
		{
			BufferedReader inFromClient = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
			PrintWriter outToClient = new PrintWriter(clientSocket.getOutputStream(), true);
			
			
			while(line != null)
			{
				try
				{
					System.out.println("Reading " + Thread.currentThread().getName());
					line = inFromClient.readLine();
				
					if(line.equals("drawcard"))
					{
						outToClient.println("Server answer: " + line.toUpperCase() + "\n");
						System.out.println("Drawing card for " + Thread.currentThread().getName());
					}
					else if(line.equals("bankroll"))
					{
						outToClient.println(getBankroll());
					}
					else if(line.equals("changecards"))
					{
						
					}
					else if(line.equals("action"))
					{
						
					}
				}
				catch(NullPointerException npe)
				{
					System.err.println(Thread.currentThread().getName() + " disconnected.");
					inFromClient.close();
					outToClient.close();
					clientSocket.close();
				}
				
			}
			
			inFromClient.close();
			outToClient.close();
		}
		catch(IOException ioe)
		{
			ioe.printStackTrace();
		}
	}
	
}